//
//  XMGMeViewController.m
//  BuDeJie
//
//  Created by Avril on 2020/3/15.
//  Copyright © 2020 Avril. All rights reserved.
//

#import "XMGMeViewController.h"
#import "UIBarButtonItem+Item.h"

@interface XMGMeViewController ()

@end

@implementation XMGMeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
    
    [self setupNavBar];
}

-(void)setupNavBar{
    
    //设置导航条内容=》栈顶控制器的navationItem决定
    self.navigationItem.title = @"我的";
    //错误，导航条内容不能由导航栏的根控制器来设置
    //self.title = @"我的";
    
    //错误，导航条内容不能由导航控制器来设置,必须通过导航控制器的栈顶控制器来设置，所以导航控制器必须有根控制器
    //    self.navigationController.navigationItem.titleView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"MainTitle"]];
        
        /**
         bug:按钮点击范围扩大，不要让按钮扩大点击范围
         原因：把UIButton按钮包装成UIBarButtonItem就有问题。
         解决办法：先把UIButton加到一个view上，再把UIView加到UIBarButtonItem上。
         
         ****/

        //右边
    //按钮的选中状态必须通过代码去设置，才可以实现
    UIBarButtonItem *nightMode =  [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"mine-moon-icon"] selectImage:[UIImage imageNamed:@"mine-moon-icon-click"] target:self action:@selector(nightClick:)];
    
    UIBarButtonItem *setting =  [UIBarButtonItem itemWithImage:[UIImage imageNamed:@"mine-setting-icon"] selectImage:[UIImage imageNamed:@"mine-setting-icon-click"] target:self action:@selector(settingClick:)];
    
    self.navigationItem.rightBarButtonItems = @[setting,nightMode];

         
  
}


//夜间模式
-(void)nightClick:(UIButton *)btn{
    
    NSLog(@"点击了夜间模式按钮");
    btn.selected = !btn.selected;
}

//
-(void)settingClick:(UIButton *)btn{
    
    NSLog(@"点击了设置按钮");
    btn.selected = !btn.selected;

}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 0;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return 0;
}

/*
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];
    
    // Configure the cell...
    
    return cell;
}
*/

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
